# Contributor: Teemu Nätkinniemi ("teepean") <tnatkinn@gmail.com>

_realname=samtools
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.16.1
pkgrel=1
pkgdesc="tools for manipulating next-generation sequencing data"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="http://www.htslib.org/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-htslib"
         "${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libdeflate")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
)
source=(https://github.com/samtools/samtools/releases/download/$pkgver/$_realname-$pkgver.tar.bz2)
sha256sums=('2fa0a25f78594cf23d07c9d32d5060a14f1c5ee14d7b0af7a8a71abc9fdf1d07')

prepare() {
  cd $srcdir/$_realname-$pkgver

  # prevent shipped htslib to be used
  rm -rf htslib-$pkgver || exit 1
}

build() {
  cd $srcdir/$_realname-$pkgver

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-htslib=system

  make
}

check() {
  cd $srcdir/$_realname-$pkgver
  make check || warning "Tests failed"
}

package() {
  cd $srcdir/$_realname-$pkgver

  make DESTDIR=$pkgdir install

  install -d $pkgdir${MINGW_PREFIX}/include/bam
  install -Dm644 *.h $pkgdir${MINGW_PREFIX}/include/bam

  install -Dm644 LICENSE $pkgdir${MINGW_PREFIX}/share/licenses/$_realname/LICENSE
}
